from Queen.datasource.base_datasource import BaseDatasource
from logger_config import logger_factory
import pandas as pd

logger = logger_factory()


class CsvDatasource(BaseDatasource):
    def __init__(self, file_path):
        super().__init__()
        self.file_path = file_path

    def read_data(self) -> pd.DataFrame:
        try:
            data = pd.read_csv(self.file_path, sep=',', dtype=str)
            logger.info(f'read csv file {self.file_path}')
            return data
        except Exception as e:
            logger.error(f'read csv file {self.file_path} fail, please check it')
            logger.error(e)
            return None
